<template>
  <view class="container">
    <!-- 标题区域 -->
    <view class="header_txt">
      <view class="back"
            @click="goback">
        <image src="../../static/img/back3.png"></image>
      </view>
      <view class="title"> 职场话题 </view>
      <view class="right">
        <image @click="toadd"
               class="edit"
               src="../../static/img/jyjq_ico_bj@2x.png"></image>
      </view>
    </view>

    <!-- 顶部导航 -->
    <view class="nav">
      <view class="all"
            :class="{active:queryParmas.type==1}"
            @click="queryParmas.type=1">全部话题</view>
      <view class="hot"
            @click="queryParmas.type=2"
            :class="{active:queryParmas.type==2}">热门话题</view>
    </view>
    <!-- 话题列表 -->
    <view class="list">
      <navigator hover-class="none"
                 :url="`/pages/topic/topicdetail?id=${item.id}`"
                 class="item"
                 v-for="item in talkList"
                 :key="item.id">
        <view class="head">
          <image :src="image"></image>
          <view class="info">
            <view class="name"> {{item.user.nickname}} </view>
            <view class="time"> {{item.createtime}} </view>
          </view>
        </view>
        <view class="middle">
          {{item.info}}
        </view>
        <view class="bottom">
          <view class="msg">
            <image src="../../static/img/消息.png"></image> {{item.cmt_nums}}
          </view>
          <view class="good">
            <image src="../../static/img/赞.png"></image> {{item.zan_nums}}
          </view>
          <view class="look">
            <image src="../../static/img/书.png"></image> {{item.read_nums}}
          </view>
        </view>
      </navigator>
    </view>
  </view>
</template>


<script>
export default {
  data() {
    return {
      queryParmas: {
        type: 1,
        page: 1,
        limit: 100
      },
      talkList: [],
      image: ''
    }
  },
  onLoad() {
    this.image = this.$serverIp + uni.getStorageSync('userinfo').avatar

    this.getList()
  },
  methods: {
    async getList() {
      let { data } = await this.$http.post('/talk/index', this.queryParmas)
      this.talkList = data.data
    },
    toadd() {
      uni.navigateTo({
        url: '/pages/issue/issue'
      })
    }
  },
  watch: {
    'queryParmas.type': {
      handler(val) {
        this.getList()
      }
    }
  }
}
</script>

<style lang="scss">
/* 头部区域 */
.header_txt {
  width: 750rpx;
  overflow: hidden;
  height: 88rpx;
  background-color: #fff;

  .back {
    position: absolute;
    top: 14rpx;
    left: 14rpx;
    width: 60rpx;
    height: 60rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    image {
      width: 48rpx;
      height: 48rpx;
    }
  }

  .right {
    position: absolute;
    top: 14rpx;
    right: 14rpx;
    width: 60rpx;
    height: 60rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .title {
    text-align: center;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    font-weight: bold;
  }
}

/* 话题列表 */
.list {
  overflow: hidden;
  .item {
    width: 750rpx;
    padding: 30rpx 50rpx 20rpx 50rpx;
    box-sizing: border-box;
    background-color: #fff;
    margin-top: 20rpx;
    .head {
      display: flex;
      image {
        height: 70rpx;
        width: 70rpx;
        border-radius: 50%;
        margin-right: 20rpx;
      }
      .info {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-around;

        .time {
          font-size: 24rpx;
          color: #999;
        }
      }
    }
    .middle {
      margin-top: 20rpx;
    }
    .bottom {
      margin-top: 20rpx;
      display: flex;
      justify-content: space-around;
      .msg,
      .good,
      .look {
        flex-grow: 1;
        display: flex;
        justify-content: center;
        align-items: center;

        image {
          width: 28rpx;
          height: 26rpx;
          margin-right: 20rpx;
        }
      }
    }
  }
}

/* 顶部导航 */
.nav {
  height: 70rpx;
  width: 750rpx;
  overflow: hidden;
  padding: 0 30rpx;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background-color: #fff;
  .active {
    position: relative;

    &::after {
      content: '';
      position: absolute;
      width: 60rpx;
      height: 4rpx;
      background-color: #ffdd47;
      bottom: -10rpx;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}

.edit {
  width: 36rpx;
  height: 36rpx;
}
</style>
